Component({

  properties: {
    statusbar: Number,
  },

  data: {
    auctionnav: [{
      name: "全部拍卖"
    }, {
      name: "热门"
    }, {
      name: "价格"
    }, {
      name: "最新"
    }, {
      name: "筛选"
    }],
    nav_checked: 0,
    maskshow: false,
    type_checked: 0,
    price_sort: 0,
    hot: 0,
    new: 0,
    ave_min: "",
    ave_max: "",
  },
  attached() {
    this.auctionData()
  },
  methods: {
    // 筛选 功能
    navalter(e) {
      var index = e.currentTarget.dataset.index
      this.setData({
        nav_checked: index
      })
      if (index == 0) {
        this.setData({
          maskshow: true
        })
        this.goodsnav()
      } else if (index == 1) {
        this.setData({
          hot: 1
        })
        this.auctionData()
      } else if (index == 2) {
        if (this.data.price_sort == 0) {
          this.setData({
            price_sort: 1
          })
        } else if (this.data.price_sort == 1) {
          this.setData({
            price_sort: 2
          })
        } else if (this.data.price_sort == 2) {
          this.setData({
            price_sort: 1
          })
        }
        this.auctionData()
      } else if (index == 3) {
        this.setData({
          new: 1
        })
        this.auctionData()
      } else if (index == 4) {
        this.setData({
          maskshow: true
        })
      }
    },
    // 类型选择
    typeLook(e) {
      var id = e.currentTarget.dataset.id
      this.setData({
        type_checked: id
      })
      this.auctionData()
    },
    // 筛选最大值/最小值
    minprice(e) {
      this.setData({
        ave_min: e.detail.value
      })
    },
    maxprice(e) {
      this.setData({
        ave_max: e.detail.value
      })
    },
    maskhide() {
      this.setData({
        maskshow: false,
        ave_min: "",
        ave_max: ""
      })
    },
    // 重置
    resetInput() {
      this.setData({
        ave_min: "",
        ave_max: ""
      })
    },
    // 完成
    fulfill() {
      this.setData({
        maskshow: false,
      })
      this.auctionData()
    },
    // 商品分类请求
    goodsnav() {
      var _this = this
      getApp().request({
        url: getApp().api.auction.type,
        method: "GET",
        success(res) {
          console.log(res)
          _this.setData({
            auction_type: res.data
          })
        }
      })
    },
    // 商品列表请求
    auctionData() {
      var _this = this
      getApp().request({
        url: getApp().api.auction.goodslist,
        method: "GET",
        data: {
          type_checked: this.data.type_checked,
          hot: this.data.hot,
          price: this.data.price_sort,
          new: this.data.new,
          ave_min: this.data.ave_min,
          ave_max: this.data.ave_max
        },
        success(res) {
          _this.setData({
            auction_list: res.data.auction_list
          })
        },
        fail(res) {
          console.log(res)
        }
      })
    },
    clickskip(e) {
      console.log(e)
      var id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/auction/details/index?id=' + id,
      })
    }
  }
})